//
//  FZHomeBannerImageSwipeViewCell.m
//
//

#import "FZHomeBannerImageSwipeViewCell.h"
#import "UIImageView+FZDefaultPlaceholder.h"

@interface FZHomeBannerImageSwipeViewCell ()

@property (strong, nonatomic) UIImageView *imageView;
@property (nonatomic) CGSize imageSize;

@end

@implementation FZHomeBannerImageSwipeViewCell

- (instancetype)initWithSize:(CGSize)size imageSize:(CGSize)imageSize {
    self = [super initWithFrame:CGRectMake(0.0, 0.0, size.width, size.height)];
    if (self) {
        self.imageSize = imageSize;
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, imageSize.width, imageSize.height)];
        self.imageView.clipsToBounds = YES;
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:self.imageView];
    }
    return self;
}

- (void)setImageURL:(NSURL *)imageURL {
    [self.imageView sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"defaultPlaceholder"]];
//    [self.imageView fz_setImageWithDefaultPlaceholderWithURL:imageURL placeholderSize:self.imageView.bounds.size completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        
//    }];
}

- (void)zoomImageWithNewHeight:(CGFloat)newHeight {
    CGSize baseSize = self.imageSize;
    CGRect baseRect = CGRectMake(CGRectGetMidX(self.imageView.frame) - baseSize.width / 2.0, 0.0, baseSize.width, baseSize.height);
    CGFloat factor = newHeight / baseSize.height;
    CGFloat newWidth = baseSize.width * factor;
    CGRect newRect = baseRect;
    newRect.origin.x -= (newWidth - baseSize.width) / 2.0;
    newRect.size.width = newWidth;
    newRect.size.height = newHeight;
    self.imageView.frame = newRect;
}

@end
